package lexer;

import java.io.InputStream;
import java.util.ArrayList;
import generatedFiles.*;


public class Lexer {
        
        private MiniJava  mj;   
        private ArrayList<Token> token; 
        
        public Lexer(InputStream ins){
                mj = new MiniJava(ins);
                token = new ArrayList<Token>();

        }
        
        public void lexicalAnalysis(ArrayList<String> lexicalError, ArrayList<String> errorImage) throws ParseException{
                Token t = new Token();
                String le = "";
                do{
                        t = mj.MiniJavaToken();
                        if(t.kind == MiniJava.ERROR){
                                le = "Lexical error at line " + 
                                t.beginLine + ", column " +
                                t.endColumn + ". Encountered: " + t.image;
                                lexicalError.add(le);  
                                errorImage.add(t.image);
                        }else{
                                token.add(t);
                        }
                }while(t.kind != MiniJava.EOF);
        }
        public void showTokens() throws ParseException{
                for(int i = 0; i < token.size(); i++){
                        System.out.println(token.get(i));
                }
        }       
}